import {
  createInbizSchema,
  createBaseSchema,
  createValidatorSchema,
  createComponentStyleSchema,
  createDecoratorStyleSchema,
  createModelSchema,
  getDefalutDecoratorProps,
  createComponentLayout,
  createControllerSchema,
} from '@inbiz/setters';
import { createBehavior, createResource } from '@inbiz/core';
import { EformTextArea as LocaleInput } from './locale';
import { getPlatform } from '@inbiz/utils';
export const defaultProps = {
  minLength: undefined,
  maxLength: undefined,
  defaultValue: '',
  placeholder: 'EformTextArea.placeholder',
  rows: undefined,
  showCount: false,
};
export const EformTextArea = createInbizSchema({
  attribute: {
    ...createBaseSchema({
      defaultValue: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input.TextArea',
      },
      placeholder: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'MultilingualInput',
      },
      rows: {
        type: 'number',
        'x-decorator': 'FormItem',
        'x-component-props': {
          min: 0,
          precision: 0,
        },
        'x-component': 'NumberPicker',
      },
      // iconPicker: {
      //   type: 'string',
      //   'x-decorator': 'FormItem',
      //   // 'x-component-props': {needType: 'group'},
      //   // 'x-component-props': {showColorPicker: false},
      //   'x-component': 'IconPicker',
      // },
      showCount: {
        type: 'boolean',
        'x-decorator': 'FormItem',
        'x-component': 'Switch',
      },
    }),
    ...createValidatorSchema(false, {
      minLength: {
        type: 'number',
        'x-decorator': 'FormItem',
        'x-component-props': {
          min: 0,
          precision: 0,
        },
        'x-component': 'NumberPicker',
      },
      'x-component-props': {
        type: 'object',
        properties: {
          maxLength: {
            type: 'number',
            'x-decorator': 'FormItem',
            'x-component-props': {
              min: 0,
              precision: 0,
            },
            'x-component': 'NumberPicker',
          },
        },
      },
    }),
  },
  style: {
    ...createComponentStyleSchema(),
    ...createComponentLayout(),
    ...createDecoratorStyleSchema(),
  },
  senior: {
    ...createModelSchema(),
    // ...createSoureSchema(),
  },
  controller: createControllerSchema({
    events: [{
      name:'onChange',
      label:'数据变更'
    }]
  })
});
export const Behavior = createBehavior({
  name: 'EformTextArea',
  extends: ['Field'],
  selector: (node) => node.props?.['x-component'] === 'EformTextArea',
  designerLocales: LocaleInput,
  designerProps: { propsSchema: EformTextArea },
});

export const Resource = createResource({
  icon: 'EformText',
  elements: [
    {
      componentName: 'Field',
      props: {
        type: 'string',
        title: {
          value: 'EformTextArea.title',
          status: true,
        },
        'x-decorator': 'FormItem',
        'x-component': 'EformTextArea',
        'x-component-props': defaultProps,
        'x-decorator-props': getDefalutDecoratorProps(getPlatform()),
      },
    },
  ],
});
